package com.example.retry.web;

import java.time.LocalTime;
import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.retry.service.HelloService;

@RestController
public class HelloController {
	
	private static final Logger log = LoggerFactory.getLogger(HelloController.class);

	@Autowired
	private HelloService helloService;

	@GetMapping("/sayHello")
	public String sayHello(@RequestParam("name") String name) {
		log.info("开始web请求---\t[{}]\t[{}]", Thread.currentThread().getId(), LocalTime.now());
		return helloService.sayHello(name);
	}

	@GetMapping("/sayHelloAsync")
	public String sayHelloAsync(@RequestParam("name") String name) {
		log.info("开始web请求---\t[{}]\t[{}]", Thread.currentThread().getId(), LocalTime.now());
		return helloService.sayHelloAsync(name);
	}	
	
	@GetMapping("/sayHelloSchedule")
	public String sayHelloSchedule(@RequestParam("name") String name) {
		log.info("开始web请求---\t[{}]\t[{}]", Thread.currentThread().getId(), LocalTime.now());
		helloService.sayHelloSchedule(name);
		return "echo:" + name;
	}
	
	@PostMapping("/batchAdd")
	public void batchAdd(@RequestBody List<String> list) {
		log.info("开始web请求---\t[{}]\t[{}]", Thread.currentThread().getId(), LocalTime.now());
		helloService.batchAdd(list);
	}
	
	
}
